package functions;

import java.util.ArrayList;

public abstract class FunctionIF implements Cloneable {
	protected double coff;
	protected double expon;

	/**
	 * this method evaluate the function
	 * 
	 * @return
	 */
	public abstract double eval(double x);

	/**
	 * this method differentiates the function and returns its derivative
	 * @return
	 */
	public abstract FunctionIF diff();
	
	/**
	 * gets the coefficient of the function
	 * @return
	 */
	public double getCoff()
	{
		return coff;
	}

	public void setCoff(double coff)
	{
		this.coff = coff;
	}
	
	/**
	 * gets the exponent of the function
	 * @return
	 */
	public double getExpon()
	{
		return expon;
	}

	public void setExpon(double expon)
	{
		this.expon = expon;
	}

	@Override
	protected abstract Object clone();
	
	//----------------------------------------------------------------
	
	
	/**
	 * this method differentiates the function if it's exponent isn't "1"
	 * i.e when call it for this function (x^2+4)^3 --> returns 3*(x^2+4)^2
	 * 
	 * @return diff of the func , this method is called by the subclass
	 */
	
	protected FunctionIF diffExponent()
	{
		FunctionIF df = (FunctionIF) clone();
		df.coff = expon * coff;
		df.expon = expon - 1;
		return df;
	}
	
}
